// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
function show_user_panel(event, element)
{
	var link = Event.element(event);
	element = $('user_panel_' + element);
	
	if (last_menu) $(last_menu).hide();
	
	var links = element.select('a')
	for(var i = 0; i < links.length; i++)
	{
		Event.observe(links[i], "mouseover", stopTimeout);
		Event.observe(links[i], "mouseout", startTimeout);
	}
		
	Event.observe(element, "mouseout", startTimeout);
	Event.observe(link, "mouseout", startTimeout);
	element.show();
	last_menu = element.id;
}

function hide_user_panel()
{
	$$('div[class="popup-user-panel"]').each(function(item) {
		item.hide();
	});
}

function showPopup(id)
{
	hidePopup();
	$(id).show();
}

function hidePopup()
{
	$$('div[class="popUp"]').each(function(item) {
		item.hide();
	});
}

var time_show = 2000;
var last_menu;

function hide_menu()
{
	//if (last_menu) $(last_menu).hide();
	hide_user_panel();
}

function stopTimeout()
{
	if (document.body.getAttribute("hide_menu_time_out") !=null)
	{
		ClearTimeOut("hide_menu_time_out");
	}
}

function startTimeout()
{
	ClearTimeOut("hide_menu_time_out");
	document.body.setAttribute("hide_menu_time_out", window.setTimeout(hide_menu, time_show));
}

function ClearTimeOut(oAttribute)
{
	var id=document.body.getAttribute(oAttribute);
	if (id !=null)
	{
		window.clearTimeout(id);
	}
	document.body.removeAttribute(oAttribute);
}
